import matplotlib.pyplot as plt
import numpy as np

# 中文显示
plt.rcParams['font.sans-serif'] = ['Microsoft YaHei']
plt.rcParams['axes.unicode_minus'] = False

def uniform_motion():
    """模拟匀速运动"""
    t = np.linspace(0, 10, 100)
    s = 2 * t  # 匀速运动，速度v=2
    
    plt.figure(figsize=(10, 6))
    plt.plot(t, s, 'b-', linewidth=2, label='s(t) = 2t')
    
    # 计算平均速度
    t0, t1 = 2, 6
    s0, s1 = 2*t0, 2*t1
    velocity = (s1 - s0) / (t1 - t0)
    
    plt.scatter([t0, t1], [s0, s1], color='red', s=100)
    plt.annotate(f't={t0}, s={s0}', (t0, s0), xytext=(t0, s0-3))
    plt.annotate(f't={t1}, s={s1}', (t1, s1), xytext=(t1, s1+1))
    
    plt.title(f'匀速运动：速度v = {velocity}')
    plt.xlabel('时间 t'); plt.ylabel('距离 s')
    plt.grid(True, alpha=0.3)
    plt.legend()
    plt.show()

uniform_motion()